package android.example.graphictest.animaiton;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.example.graphictest.R;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class TweenAnimation extends Activity 
{
	public static long starttime;
	public static long endtime;
	public static float fps;
	public static long duration;
	public static long lasttime;
	Animation tweenAnimation;
	Timer timer;
	TimerTask task = new TimerTask(){
			public void run()
			{
				Message msg = new Message();
				msg.what    = 0;
				mHandler.sendMessage(msg);
				
			}
		};
		Handler mHandler = new Handler(){
			public void handleMessage(Message msg)
			{
			  switch(msg.what)
			  {
			    case 0: setTitle("Animation FPS Test "
			    		+"with Rotating 20 times ");break;
			  }
			  
			  super.handleMessage(msg);
			  
			}
		};
	protected void onCreate(Bundle savedInstanceState) 
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.tween_animation);
        timer = new Timer();
        timer.schedule(task,10, 1000);
	    
	    ImageView imageview  =  (ImageView)findViewById(R.id.imageviewa);
	    tweenAnimation       =  AnimationUtils.loadAnimation(this, R.anim.animation_rotate);
	    imageview.startAnimation(tweenAnimation);
	    tweenAnimation.setAnimationListener(new Animation.AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				starttime =  System.currentTimeMillis();
				duration  =  tweenAnimation.computeDurationHint();
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				endtime  =  System.currentTimeMillis();
			    lasttime = endtime  - starttime ;
			    fps = ((float)20*1000)/(lasttime -duration );
			    TweenAnimation.this.finish();
			} 
		});


	    
	}

}
